package epam.com.study.xml.classes;

import java.io.File;
import java.io.FileNotFoundException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

public class ParserJAXB {
	public static ListOfStones loadJAXB(String fileName) throws JAXBException, FileNotFoundException{
		/*
		        // test unload
				JAXBContext context = JAXBContext.newInstance(ListOfStones.class);
				Marshaller m = context.createMarshaller();
				ListOfStones list = new ListOfStones();
				Stone stone = new Stone();
				stone.setId(111);
				stone.setName("elemet 1");
				stone.setPreciousness(TypeOfStonesEnum.JEWEL);
				VisualParameters vis = new VisualParameters();
				vis.setEdge(55);
				stone.setVisualParameters(vis);
				list.addStone(stone);
				Stone stone2 = new Stone();
				stone2.setId(222);
				stone2.setName("element 2");
				
				list.addStone(stone2);
				m.marshal(list, new FileOutputStream("src/main/resources/Jewel11.xml"));
			*/	

				File file = new File(fileName);
				JAXBContext jaxbContext = JAXBContext.newInstance(ListOfStones.class);
		 		Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
		 		ListOfStones list = (ListOfStones)jaxbUnmarshaller.unmarshal(file);
		 		
		 		return list;
			}
			
}
